<template>
    <div>
        <h1>科室列表</h1>
        科室名称:<input type="text" v-model="info.name" >
        选择科室:<select v-model="info.oid">
            <option value="">请选择</option>
            <option :value="item.oid" v-for="item in level" :key="item.oid">{{item.oname}}</option>  
        </select>
        <input type="button" value="查询" @click="GetList">
        <table class="table table-bordered" style="background-color:lightskyblue;">
            <tbody>
                <tr>
                    <td>科室名称</td>
                    <td>科室人数</td>
                    <td>科室描述</td>
                    <td>创建日期</td>
                    <td>操作</td>
                </tr>
                <tr v-for="value in getlist">
                    <td>{{value.name}}</td>
                    <td>{{value.people}}</td>
                    <td>{{value.introduce}}</td>
                    <td>{{value.createTime.substr(0,10)}}</td>
                    <td><input type="button" value="详情" @click="Fan(value.id)" style="background-color:aqua;">
                        <input type="button" value="修改" @click="update(value.id)" style="background-color:aquamarine;">
                        <input type="button" value="删除" @click="Del(value.id)" style="background-color:red;"></input>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue'
import { useRoute,useRouter } from 'vue-router';
let route=useRoute();
let router=useRouter();

let getlist:any=ref([])
let level:any=ref([]);

let info:any=ref({
    name:"",
    oid:""
});

onMounted(()=>{
    GetList();
    Getlevel();
})
//删除
const Del=(id:any)=>{
    let f=(confirm("确认要删除吗?"))
    axios({
        url:'https://localhost:7292/api/Office/Del',
        method:'delete',
        params:{
            id:id
        }
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0){
            alert("删除成功!");
            GetList();
        }
        else{
            alert("删除失败");
            return;
        }
    })
    .catch((err)=>{
        console.log(err);
    })
}
//跳转详情
const Fan=(id:any)=>{
    router.push({
        path:'/fanOffice',
        query:{
            id:id
        }
    })
}
//跳转修改
const update=(id:any)=>{
    router.push({
        path:'/updateOffice',
        query:{
            id:id
        }
    })
}
//显示
const GetList=()=>{
    axios({
        url:'https://localhost:7292/api/Office/GetListOffice',
        method:'get',
        params:info.value
    })
    .then((res)=>{
        console.log(res);
        getlist.value=res.data
    })
    .catch((err)=>{
        console.log(err);
    })
}
//下拉
  const Getlevel=()=>{
     axios({
        url:'https://localhost:7292/api/Office/GetLevelOffcie',
        method:'get',
     })
     .then((res)=>{
        console.log(res);
        level.value=res.data
     })
     .catch((err)=>{
        console.log(err);
     })
  }
</script>

<style scoped>

</style>
